This page last changed on Oct 25, 2006 by ross.

The Smtp transport provider can be used to for sending messages over Smtp and Smtps (secure) using the javax.mail api. The implementation supports CC/BCC/ReplyTo addresses, attachments, custom Header properties and customisable authentication. It also provides support for javax.mail.Message transformation.

The javadoc for this provider can be found here ,

org.mule.providers.email.SmtpConnector org.mule.providers.email.SmtpsConnector

Smtp Connector Properties

Property Description Default Required
subject A default subject for the outbound message if one is not set. (no subject) No
fromAddess The from address to set on the outgoing message.   Yes
ccAddresses A comma separated list of email messages to carbon copy to.   No
bccAddresses A comma separated list of email messages to blind carbon copy to.   No
replyToAddresses A comma separated list of email messages that will receive replies to the mail message sent from this connector   No
customHeaders A Map of custom header properties that will be set on the outgoing message. Property variables can be used in the headers to be resolved at runtime, i.e. ${my.variable}. These properties are resolved against the MuleManager properties and any properties set on the current event and endpoint.   No
authenticator Is used when sending authenticated Smtp requests. By default Mule handles authentication by creating a default Authenticator if there are user credentials set on the Smtp endpoint (see below). Users can customise the authenticator if needed by setting this to their oun authenticator. Authenitcators must implement javax.mail.Authenticator   No
contentType Sets the default Mime content type for outgoing message text/plain No
Server Credentials

The host, port, and user credentials are set on the smtp:// endpoint and the additional properties on the connector act as defaults if the same properties are not set on the endpoint.

Smtps Connector Properties

The Smtps Connector enables Smtp over SSL using the javax.mail APIs. It supports all the properties of the Smtp connector and has some additional properties for setting up an SSL connection.

Property Description Default Required
socketFactory The SSL socket factory to use javax.net.ssl.SSLSocketFactory No
socketFactoryFallback Whether to enable fallback false No
trustStore The flie location of a trust store   No
trustStorePassword The password for the trust store   No

When using the Smtps Connector the default port is set to 465.

Smtp(s) Endpoints

Smtp endpoints describe details about the Smtp server and the recipients of messages sent from the Smtp endpoint. Smtp URIs use the following syntax -

smtp://[user:password@]<smtp server>[:port]?address=<recipient address>

The format is the same for Smtps -

smtps://[user:password@]<smtp server>[:port]?address=<recipient address>
Escape your credentials

Sometimes you'll have illegal (for URI) characters in your login/password. Use the standard escape syntax your browser would use, e.g. the username user@mule would become user%40mule.

For example,

Will send mail using smtp.mail.yahoo.co.uk (using default smtp port) to the address [email protected]. The Smtp request is authenticated using username muletestbox and password 123456.

You will probably want to set other information such as subject and fromAddress. These can be set as parameters on the URI but we recommend you set them as endpoint properties to make it easier to read and maintain the configuration.

<endpoint address="smtp://muletestbox:[email protected]?
                              [email protected]">
    <properties>
        <property name="fromAddress" value="[email protected]"/>
        <property name="ccAddresses" value="[email protected],[email protected]"/>
        <property name="subject" value="Please verify your ebay account details"/>
    </properties>
</endpoint>

So far, all configurations has been static in that you define all the information in the configuration of the endpoint. However, you can set the following properties on the MuleMessage to control the settings of the outgoing Smtp Message. These properties will override the endpoint properties -

Constant Name Description
MailProperties.TO_ADDRESSES_PROPERTY toAddresses comma-separate list of addresses
MailProperties.CC_ADDRESSES_PROPERTY ccAddresses comma-separate list of addresses
MailProperties.BCC_ADDRESSES_PROPERTY bccAddresses comma-separate list of addresses
MailProperties.REPLY_TO_ADDRESSES_PROPERTY replyToAddresses comma-separate list of addresses
MailProperties.FROM_ADDRESS_PROPERTY fromAddress single email address
MailProperties.SUBJECT_PROPERTY subject The email subject string
MailProperties.CUSTOM_HEADERS_MAP_PROPERTY customHeaders A Map of string header properties
MailProperties.CONTENT_TYPE_PROPERTY contentType The Mime content type of the message

If you always want to set the email address dynamically, you can leave out the address parameter on the Smtp endpoint.

Transformers

There are a couple of transformers provided with the Email transport that are useful for converting Object payloads to javax.mail.Message types. These transformers adhere to the rules listed above and handle attachments too. If you need to customise the behaviour of these transformers it is recommended that you extends the existing transformers rather than re-implement them.

Transformer Description
org.mule.providers.email.transformers. StringToEmailMessage Converts a String message payload to a javax.mail.Message. This transformer doesn't support attachements and is deprecated in favour of the ObjectToMimeMessage transformer
org.mule.providers.email.transformers. ObjectToMimeMessage Converts an Object message payload to a javax.mail.Message. Supports attachments.
Document generated by Confluence on Nov 27, 2006 10:27